﻿using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Microsoft.Xna.Framework;
using Sharpie;
using System.IO;
using System.Collections.Generic;
using Android.Content.PM;

namespace SharpieAndroid
{
    [Activity(Label = "Sharpie", MainLauncher = true, Icon = "@drawable/snake", Theme = "@android:style/Theme.NoTitleBar", ScreenOrientation = ScreenOrientation.Landscape)]
    public class Activity1 : AndroidGameActivity
    {
        public static string AppDataPath = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.Path, "Sharpie");
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            if (!Directory.Exists(AppDataPath))
            {
                Directory.CreateDirectory(AppDataPath);
            }
            string loaderror;
            if (!Config.Load(out loaderror))
            {
                // TODO: show error message
                Config.RestoreDefault(Assets);
            }

            Main.Activity = this;
            Main main = new Main();
            SetContentView(main.Window);
            main.Run();
        }

        protected override void OnDestroy()
        {
            base.OnDestroy();
            string saveerror;
            Config.Save(out saveerror);
            if (saveerror != "")
            {
                // TODO: show save error message
            }
        }

        protected override void OnPause()
        {
            base.OnPause();
        }

        public override void OnBackPressed()
        {
            base.OnBackPressed();
        }

        protected override void OnResume()
        {
            base.OnResume();
        }
    }
}

